﻿using System.Collections.Generic;
using System.Linq;
using DynamicData;

namespace LuckyCoding.Models;

public class DispositionModel
{
    public string? RunOrder { get; set; }
    public bool IsUseFolder { get; set; }
    public string[] Args { get; set; }
    public string[] Prompt { get; set; }
}

public static class DispositionModelStatic
{
    public static string[] BuildOrder(this DispositionModel model,Dictionary<string,string> dictionary,string? folderPath = null)
    {
        List<string> list = new List<string>();
        if (model.IsUseFolder || !string.IsNullOrEmpty(folderPath)) list.Add($"cd {folderPath}");
        string[]? split = model.RunOrder?.Split("\n");
        if (split != null)
        {
            var s = split[^1];
            s = dictionary.Aggregate(s, (current, variable) => current.Replace(variable.Key, variable.Value));
            s += $" {model.Args.Aggregate(" ", (current, arg) => current + arg)}";
            split[^1] = s;
        }
        list.Add(split!);
        return list.ToArray();
    }
}